package cn.ibizlab.odoo.core.odoo_website.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iwebsite_menu;
import cn.ibizlab.odoo.core.odoo_website.domain.Website_menu;
import cn.ibizlab.odoo.core.odoo_website.filter.Website_menuSearchContext;
import cn.ibizlab.odoo.core.odoo_website.service.IWebsite_menuService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[网站菜单] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Website_menuServiceImpl implements IWebsite_menuService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iwebsite_menuClientService website_menuClientService;

    @Override
    public boolean update(Website_menu website_menu) {
        boolean bOk = false ;
        Iwebsite_menu clientModel = this.convert2Model(website_menu,null);
        website_menuClientService.update(clientModel) ;
        this.convert2Domain(clientModel,website_menu) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Website_menu get(Integer id) {
        Iwebsite_menu clientModel = website_menuClientService.createModel();
        clientModel.setId(id);
        website_menuClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Website_menu get(Website_menu website_menu) {
        Website_menu retwebsite_menu = this.get(website_menu.getId()) ;
    	BeanCopier copier=BeanCopier.create(retwebsite_menu.getClass(), website_menu.getClass(), false);
        copier.copy(retwebsite_menu, website_menu, null);
        return website_menu ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iwebsite_menu clientModel = website_menuClientService.createModel();
        clientModel.setId(id);
        website_menuClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Website_menu> website_menus, int batchSize) {

                        //website_menuClientService.createBatch(website_menus,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //website_menuClientService.removeBatch(website_menus) ;

    }

    @Override
    public void updateBatch(List<Website_menu> website_menus, int batchSize) {

        //website_menuClientService.updateBatch(website_menus,batchSize) ;

    }

    @Override
    public boolean create(Website_menu website_menu) {
        boolean bOk = false ;
        Iwebsite_menu clientModel = this.convert2Model(website_menu,null);
        website_menuClientService.create(clientModel) ;
        this.convert2Domain(clientModel,website_menu);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Website_menu> searchDefault(Website_menuSearchContext context) {
        List<Website_menu> list = new ArrayList<Website_menu>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_menu> clientModelList = website_menuClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_menu clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_menu>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Website_menu> selectByOdoo_create(Integer id){
        Website_menuSearchContext context = new Website_menuSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Website_menu> list = new ArrayList<Website_menu>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_menu> clientModelList = website_menuClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_menu clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_menu>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Website_menu> selectByOdoo_write(Integer id){
        Website_menuSearchContext context = new Website_menuSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Website_menu> list = new ArrayList<Website_menu>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_menu> clientModelList = website_menuClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_menu clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_menu>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据网站菜单查询
     */
    @Override
    public Page<Website_menu> selectByOdoo_parent(Integer id){
        Website_menuSearchContext context = new Website_menuSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Website_menu> list = new ArrayList<Website_menu>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_menu> clientModelList = website_menuClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_menu clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_menu>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据页查询
     */
    @Override
    public Page<Website_menu> selectByOdoo_page(Integer id){
        Website_menuSearchContext context = new Website_menuSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Website_menu> list = new ArrayList<Website_menu>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_menu> clientModelList = website_menuClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_menu clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_menu>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iwebsite_menu convert2Model(Website_menu domain , Iwebsite_menu model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = website_menuClientService.createModel() ;
        }

         if(domain.getTheme_template_idDirtyFlag())
            model.setTheme_template_id(domain.getTheme_template_id());
         if(domain.getIs_visibleDirtyFlag())
            model.setIs_visible(domain.getIs_visible());
         if(domain.getUrlDirtyFlag())
            model.setUrl(domain.getUrl());
         if(domain.getNew_windowDirtyFlag())
            model.setNew_window(domain.getNew_window());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getParent_pathDirtyFlag())
            model.setParent_path(domain.getParent_path());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWebsite_idDirtyFlag())
            model.setWebsite_id(domain.getWebsite_id());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getChild_idDirtyFlag())
            model.setChild_id(domain.getChild_id());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getPage_id_textDirtyFlag())
            model.setPage_id_text(domain.getPage_id_text());
         if(domain.getParent_id_textDirtyFlag())
            model.setParent_id_text(domain.getParent_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getPage_idDirtyFlag())
            model.setPage_id(domain.getPage_id());
         if(domain.getParent_idDirtyFlag())
            model.setParent_id(domain.getParent_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Website_menu convert2Domain( Iwebsite_menu model ,Website_menu domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Website_menu();
        }

        if(model.getTheme_template_idDirtyFlag())
            domain.setTheme_template_id(model.getTheme_template_id());
        if(model.getIs_visibleDirtyFlag())
            domain.setIs_visible(model.getIs_visible());
        if(model.getUrlDirtyFlag())
            domain.setUrl(model.getUrl());
        if(model.getNew_windowDirtyFlag())
            domain.setNew_window(model.getNew_window());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getParent_pathDirtyFlag())
            domain.setParent_path(model.getParent_path());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWebsite_idDirtyFlag())
            domain.setWebsite_id(model.getWebsite_id());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getChild_idDirtyFlag())
            domain.setChild_id(model.getChild_id());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getPage_id_textDirtyFlag())
            domain.setPage_id_text(model.getPage_id_text());
        if(model.getParent_id_textDirtyFlag())
            domain.setParent_id_text(model.getParent_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getPage_idDirtyFlag())
            domain.setPage_id(model.getPage_id());
        if(model.getParent_idDirtyFlag())
            domain.setParent_id(model.getParent_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
